package com.ChefApp.mobile;

import java.util.Vector;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageItemAdapter extends BaseAdapter {
	private final Vector<ListItemWithImage> items;
	
	public ImageItemAdapter(final Context context, final int itemResId,
            final Vector<ListItemWithImage> items) {
        this.items = items;
    }

    public int getCount() {
        return this.items.size();
    }

    public Object getItem(int position) {
        return this.items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {

        final ListItemWithImage item = this.items.get(position);
        View itemView = null;
        if (item.getType()=="online") { 
        	if (convertView == null) {
        		LayoutInflater inflater = (LayoutInflater) parent.getContext()
        				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        		itemView = inflater.inflate(R.layout.image_row, null);
        	} else {
        		itemView = convertView;
        	}

        	// Set the text of the item
        	TextView tvUname= (TextView) itemView.findViewById(R.id.textViewUname);
        	tvUname.setHeight(0);
        	TextView txtName = (TextView) itemView.findViewById(R.id.textTitle);
        	txtName.setText(item.getTitle());
        	TextView untertitel = (TextView) itemView.findViewById(R.id.textSub);
        	untertitel.setText(item.getSubtitle());
        	TextView tvdate = (TextView) itemView.findViewById(R.id.textDate);
        	tvdate.setText(item.getDatum());
        	TextView tvAufwand = (TextView) itemView.findViewById(R.id.textAufwand);
        	tvAufwand.setText(item.getAufwand());
        	// Set the check-icon
        	ImageView imgViewrec = (ImageView) itemView
        			.findViewById(R.id.imagerec);
        	imgViewrec.setImageBitmap(item.getBild());

        	ImageView imgViewhow = (ImageView) itemView.findViewById(R.id.imagehow);
        	Bitmap bigger = Bitmap.createScaledBitmap(item.getBewertung(), 115, 30, false);
        	imgViewhow.setImageBitmap(bigger);
        } else if (item.getType()=="archiv") {
        	if (convertView == null) {
        		LayoutInflater inflater = (LayoutInflater) parent.getContext()
        				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        		itemView = inflater.inflate(R.layout.image_row, null);
        	} else {
        		itemView = convertView;
        	}

        	// Set the text of the item
        	TextView txtName = (TextView) itemView.findViewById(R.id.textTitle);
        	txtName.setText(item.getTitle());
        	TextView untertitel = (TextView) itemView.findViewById(R.id.textSub);
        	untertitel.setText(item.getSubtitle());
        	TextView tvdate = (TextView) itemView.findViewById(R.id.textDate);
        	tvdate.setText(item.getDatum());
        	TextView tvAufwand = (TextView) itemView.findViewById(R.id.textAufwand);
        	tvAufwand.setText(item.getAufwand());
        	TextView tvUname= (TextView) itemView.findViewById(R.id.textViewUname);
        	tvUname.setText(item.getuName());
        	ImageView imgViewrec = (ImageView) itemView
        			.findViewById(R.id.imagerec);
        	imgViewrec.setImageBitmap(Bitmap.createScaledBitmap(item.getBild(),115,100,false));

        	
        	
        	
        }
        return itemView;

    }

}
